package com.wuyi.tea.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wuyi.tea.domain.pojo.Order;
import com.wuyi.tea.domain.vo.OrderDetailVO;
import com.wuyi.tea.domain.vo.OrderVO;
import com.wuyi.tea.domain.vo.R;
import com.wuyi.tea.service.OrderService;
import com.wuyi.tea.util.LocalStorageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

@Slf4j
@Api(tags = "订单模块")
@RestController(value = "AdminOrderController")
@RequestMapping("/admin/order")
public class OrderController {

    @Resource
    private OrderService orderService;

    @ApiOperation("获取订单列表")
    @GetMapping("list")
    public R list(
                    @RequestParam(name = "page",defaultValue = "1",required = false) Integer page,
                    @RequestParam(name = "pageSize",defaultValue = "5",required = false) Integer pageSize
                ){

        log.info("id为{}的用户获取了订单列表,page: {} , pageSize: {}", LocalStorageUtil.get(),page,pageSize);
        Page<OrderVO> orderVOPage = orderService.getAdminOrderList(page,pageSize);
        return R.success(orderVOPage);
    }

    @ApiOperation("获取订单详情")
    @GetMapping("/detail")
    public R getOrderDetail(@RequestParam("orderId") Long orderId){

        log.info("id为{}的用户获取了订单详情，订单id: {}",LocalStorageUtil.get(),orderId);
        OrderDetailVO orderDetail = orderService.getOrderDetail(orderId);
        return R.success("订单获取成功",orderDetail);
    }

}
